package algorithm.leetcode;

import org.apache.commons.lang.StringUtils;

/**
 * @program: util
 * @description: 目标字符串中找到第一个符合给定字符串的下标
 * @author: zhouliangliang
 * @create: 2021-04-16 10:35
 **/
public class SubStr {

    private int searchIndex(String content, String searched) {
        if(StringUtils.isEmpty(searched)) {
            return 0;
        }

        for(int i = 0; i <= content.length() - searched.length(); i++) {
            if(content.substring(i, i + searched.length()).equals(searched)) {
                return i;
            }
        }

        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new SubStr().searchIndex("abcba","ab"));
    }
}
